home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/usr/bin/perl ############################################################################ # # TableMaker by Sam Choukri # Copyright 1995, 1996 # version 1.0.1 # January 22, 1996 # # If you want to redistribute TableMaker, please include ALL the files in # their ORIGINAL STATE, including the Runtime or Droplet version of the # TableMaker application, documentation, and the default settings file. Do # not under any circumstances redistribute just this file -- the actual # TableMaker MacPerl script. # # You can modify this script to suit your needs, but do not redistribute # your modified copy. I don't claim to be a good Perl programmer. If you # make changes that improves the efficiency or adds new features, send me # a copy of the modified script and I'll consider incorporating the changes # into the next released version of TableMaker. # # Remember, TableMaker is shareware. If you feel it has been helpful to # you, please send five US dollars to: # # Sam Choukri # 406 Tucker Hall, UMC # Columbia, MO 65211 # # TableMaker started out as a web page and then was converted into a stand # alone version after popular demand. Check out TableMaker on the web at # <http://www.missouri.edu/~c588349/tablemaker.html>. # # You can send me e-mail at <sam@pobox.com> if you'd like. # ############################################################################ # check to see if there were any files dropped on TableMaker if (@ARGV == 0) {&MacPerl'Answer("To use TableMaker, you need to drag and drop one or more data files onto it.\n\nPlease quit and try again.", "Quit"); &MacPerl'Quit(1); # automatically quits MacPerl Runtime version exit; } ################################################### # these are the required functions from "GUSI.ph" sub AF_FILE { 4; } sub pack_sa_constr_file { local($count, $constr, $cur) = (0, ""); while ($cur = shift) { ++$count; $constr .= pack("A4", $cur); } pack("s", $count) . $constr; } ################################################### $settingsfile = &MacPerl'Choose( &AF_FILE, 0, "Select a settings file:", &pack_sa_constr_file("TEXT")); require "$settingsfile"; if (($BOLD_CAPTION eq 'YES') && ($CAPTION ne '')) { $CAPTION = "<B>" . $CAPTION . "<\/B>";} while (@ARGV > 0) { $arg = shift(@ARGV); &find($arg), next if -d $arg; &searchLoop($arg); next if -f $arg; } sub searchLoop { local ($thefilename) = @_; # create an output html file and start printing to it # but first make sure the output filename won't exceed 31 chars # ------------------------------------------------------------- @temp = split(/:/,$thefilename); while (length($temp[$#temp]) > 26) {chop $temp[$#temp];} $outputfile = join(':', @temp) . ".html"; open(OUTPUT, ">".$outputfile) || die "Can't write to file\n"; &MacPerl'SetFileInfo($CREATOR, "TEXT", $outputfile) ; print OUTPUT <<ENDOFTEXT; <HTML> <HEAD><title>TableMaker Output</title></HEAD> <BODY> <H1>TableMaker Output</H1> ENDOFTEXT $/ = ""; # enable paragraph mode for input $* = 1; # enable multi-line patterns for search/replace open(THEFILE, $thefilename) || die "Can't open file $thefilename\n"; while ($data = <THEFILE>) { # by default, format all cells as data cells # ------------------------------------------ $data =~ s/((\r)+)/\n/g; $data =~ s/((\n)+)/\n/g; $data =~ s/^(.*)$/<TR>\n <TD>$1<\/TD>\n<\/TR>/g; $data =~ s/$DELIMITER/<\/TD>\n <TD>/go; $HEADER =~ tr/[a-z]/[A-Z]/; # make sure input is in all caps # change the formatting of the first row to header cells # ------------------------------------------------------ if (($HEADER eq 'FIRST ROW') || ($HEADER eq 'FIRST ROW AND COLUMN')) { $data =~ s/((\n)+)//g; $* = 0; $data =~ s/<\/TR>(.*)<\/TR>/<\/TR><TEMPORARY_DATA><\/TR>/g; $TEMPORARY_DATA = $1; $data =~ s/<TD>/<TH>/g; $data =~ s/<\/TD>/<\/TH>/g; $data =~ s/<TEMPORARY_DATA>/$TEMPORARY_DATA/g; $* = 1; $data =~ s/<TR>/<TR>\n/g; $data =~ s/<\/T([DHR])>/<\/T$1>\n/g; $data =~ s/<\/TR>(\n)+/<\/TR>\n/g; } # change the formatting of the first column to header cells # --------------------------------------------------------- if (($HEADER eq 'FIRST COLUMN') || ($HEADER eq 'FIRST ROW AND COLUMN')) { $data =~ s/<TR>\n <TD>(.*)<\/TD>/<TR>\n <TH>$1<\/TH>/g; } # change the formatting of all cells to header cells # -------------------------------------------------- if ($HEADER eq 'ALL CELLS') { $data =~ s/<TD>/<TH>/g; $data =~ s/<\/TD>/<\/TH>/g; } # look for row and column spanning codes # -------------------------------------- $SPANNING =~ tr/[a-z]/[A-Z]/; # make sure input is in all caps if ($SPANNING eq 'YES') { $data =~ s/<T([DH])>\(colspan=([\d]*)\)/<T$1 COLSPAN=$2>/gi; $data =~ s/<T([DH])>\(cs=([\d]*)\)/<T$1 COLSPAN=$2>/gi; $data =~ s/<T([DH])>\(rowspan=([\d]*)\)/<T$1 ROWSPAN=$2>/gi; $data =~ s/<T([DH])>\(rs=([\d]*)\)/<T$1 ROWSPAN=$2>/gi; } # specify the horiz alignment for all cells in a row # -------------------------------------------------- $ROW_ALIGN =~ tr/[a-z]/[A-Z]/; # make sure input is in all caps if ($ROW_ALIGN ne 'DEFAULT') { $data =~ s/<TR>/<TR ALIGN=$ROW_ALIGN>/g; } # specify the horiz alignment for all data cells # ---------------------------------------------- $TD_ALIGN =~ tr/[a-z]/[A-Z]/; # make sure input is in all caps if ($TD_ALIGN ne 'DEFAULT') { $data =~ s/<TD/<TD ALIGN=$TD_ALIGN/g; } # specify the horiz alignment for all header cells # ------------------------------------------------ $TH_ALIGN =~ tr/[a-z]/[A-Z]/; # make sure input is in all caps if ($TH_ALIGN ne 'DEFAULT') { $data =~ s/<TH/<TH ALIGN=$TH_ALIGN/g; } # choose how the table source is formatted # ---------------------------------------- $SOURCE_LINES =~ tr/[a-z]/[A-Z]/; # make sure input is in all caps if ($SOURCE_LINES eq 'SAME') { $data =~ s/<\/T([DH])>\n \<T([DH])/<\/T$1> \<T$2/g; } # build table tags # ---------------- $TABLE = "<TABLE"; if ($BORDER ne '') {$TABLE .= " BORDER=$BORDER";} if ($WIDTH ne '') {$TABLE .= " WIDTH=\"$WIDTH\"";} if ($HEIGHT ne '') {$TABLE .= " HEIGHT=\"$HEIGHT\"";} if ($CELLPADDING ne '') {$TABLE .= " CELLPADDING=$CELLPADDING";} if ($CELLSPACING ne '') {$TABLE .= " CELLSPACING=$CELLSPACING";} $TABLE .= ">\n"; if ($CAPTION ne '') {$TABLE .= "<CAPTION ALIGN=$ALIGN_CAPTION>$CAPTION</CAPTION>\n";} $TABLE .= $data; $TABLE .= "\n</TABLE>"; # print the source of each table in the html file # ----------------------------------------------- print OUTPUT <<ENDOFTEXT; <HR> <!--BEGIN SOURCE OF TABLE--> $TABLE <!--END SOURCE OF TABLE--> ENDOFTEXT } # end while print OUTPUT <<ENDOFTEXT; </BODY> </HTML> ENDOFTEXT close(OUTPUT); } # end searchLoop &MacPerl'Answer("Job complete.\n\nThanks for using TableMaker.", "OK"); &MacPerl'Quit(1); # automatically quits MacPerl Runtime version exit;